{extend name='admin@public/content'}

{block name="button"}
<button data-open='{:url("$classuri/")}' data-title="返回列表" class='layui-btn layui-btn-sm layui-btn-primary'><i class='fa fa-arrow-left'></i> 返回列表</button>
{/block}

{block name='content'}

<!--右侧编辑区 开始-->
<div class="panel panel-default article-right" style="overflow:hidden;width: 96rem;">
    <div class="panel-body">
        <form class="form-horizontal" action="{:url()}" data-auto="true" method="post">
            <input type="hidden" name="id" value='{$vo.id|default=""}'>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">体检中心名称</span>
                        <input class="layui-input rw60" maxlength="200" required="required"  name="name" value="{$vo.name|default=''}" title="体检中心名称不能为空哦" placeholder="输入体检中心名称">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">体检中心类型</span>
                        <select name='category_id' class='input-sm form-control' style="width:20rem;">
                            {foreach $category as $key=>$cate}
                            <option  {if isset($vo)}{if condition="$vo.category_id eq $key"}selected{/if}{/if} value='{$key}'>{$cate}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">团检体检中心</span>
                        <label class="think-checkbox">
                            <input type="checkbox" name="is_team" value="1" {if isset($vo)}{if condition="$vo.is_team eq 1"}checked{/if}{/if} style="margin-left: 0.6rem;"/>&nbsp;是
                        </label>
                        <label class="think-checkbox">
                            <input type="checkbox" name="is_team" value="0" {if isset($vo)}{if condition="$vo.is_team eq 0"}checked{/if}{/if} style="margin-left: 0.6rem;"/>&nbsp;否
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">医院标签</span>
                        {foreach $tags_list as $key=>$item}
                        <label class="think-checkbox">
                            <input type="checkbox" name="tags[]" {if isset($tagsArr)}{if condition="in_array($item, $tagsArr)"}checked{/if}{/if}  value="{$item}" style="margin-left: 0.6rem;"/>{$item}
                        </label>
                        {/foreach}
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">唯一编号</span>
                        <input class="layui-input rw20" name='unique_code' value="{$vo.unique_code|default=''}">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">所在城市</span>
                        <select required name='province_id' id="province_id" class='layui-select rw15'>
                        </select>
                        <select required name='city_id' id="city_id" class='layui-select rw15'>
                        </select>
                        <select required name='district_id' id="district_id" class='layui-select rw15'>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">详细地址</span>
                        <input class="layui-input rw60" name='address' value="{$vo.address|default=''}">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">咨询电话</span>
                        <input class="layui-input rw60" name='phone' value="{$vo.phone|default=''}">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">工作时间</span>
                        <input class="layui-input rw60" name='worktime' value="{$vo.worktime|default=''}">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">选择人数</span>
                        <input class="layui-input rw60" type="number"  name='peoplesnum' value="{$vo.peoplesnum|default=''}">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">推荐指数</span>
                        <input class="layui-input rw60" type="number"  name='recpoints' value="{$vo.recpoints|default=''}" placeholder="1~5">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">地址坐标</span>
                        <div class="layui-form-item layui-inline" style="margin-bottom: 0rem;">
                            <label class="layui-form-label rw5">经度</label>
                            <div class="layui-input-inline rw12">
                                <input id="data_lat" name="lat" value="{$vo.lat|default=''}" class="layui-input">
                            </div>
                            <label class="layui-form-label rw5">维度</label>
                            <div class="layui-input-inline rw12">
                                <input id="data_lng" name="lng" value="{$vo.lng|default=''}" class="layui-input">
                            </div>
                            <a data-modal='{:url("$classuri/map")}' data-title="设置" class='layui-btn layui-btn-sm layui-btn-primary'><i class='fa fa-arrows'></i> 设置</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="input-group">
                        <span class="input-group-addon rw12">联系电话</span>
                        <input class="layui-input rw20" name='phone' title="联系电话不能为空哦" placeholder="设置联系电话" value="{$vo.phone|default=''}">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12">
                    <div class="form-control" style="height:auto">
                        <label style="color:#333;font-size: 12px;">LOGO设置</label>
                        <div class="row nowrap">
                            <div class="col-xs-3" style="width:160px;">
                                <div class="upload-image-box" style="background-image: url('{$vo.logo|default=$image}')">
                                    <input value="{$vo.logo|default=''}" type="hidden" name="logo">
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <br>
                                <a data-file="one" data-type="jpg,png,jpeg" data-field="logo" class="btn btn-sm">上传图片</a>
                            </div>
                        </div>
                        <p class="help-block" style="margin-top:10px;color:#ccc;font-size: 12px;">图片建议尺寸：1:1</p>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">相册图片</label>
                <div class="row nowrap">
                    <div class="col-xs-6">

                        <input type="hidden" name="photos" id="photos" value="{$vo.photos|default=''}" data-srcs="{$vo.photos|default=''}">
                    </div>
                </div>
                <p class="help-block" style="margin-top:10px;color:#ccc;font-size: 12px;">图片建议尺寸：1:1</p>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <div class="form-control" style="height:auto">
                        <label style="color:#333;font-size: 1.2rem;margin-bottom: 1rem">介绍文字</label>
                        <textarea name="intro">{$vo.intro|default=""}</textarea>
                    </div>
                </div>
            </div>

            <div class="form-actions">
                <div class="row">
                    <div class="layui-form-item text-center">
                        <button class="layui-btn" type='submit'>保存数据</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<!--右侧编辑区 结束-->

{/block}


{block name='script'}
<script>
    var areas = JSON.parse('{$area_list|raw}');
    var selectIndexP = {$vo.province_id|default="0"};
    var selectIndexC = {$vo.city_id|default="0"};
    var selectIndexS = {$vo.district_id|default="0"};
    var selectP = 0;

    $(function () {
        $('body').on('change', '.upload-image-box input', function () {
            $('.news-item.active').css('background-image', 'url(' + this.value + ')');
            $(this).parent('.upload-image-box').css('background-image', 'url(' + this.value + ')');
        });
        $('#photos').uploadMultipleImage();
        $('#province_id').change(function() {
            var id = $(this).children('option:selected').val();
            selectP = id;
            $("#city_id").empty();

            $.each(areas[id].city, function(idx, obj) {
                var selected = false;
                if (obj.id == selectIndexC) {
                    selected = true;
                }
                $("#city_id").append(new Option(obj.name, obj.id, false, selected));
            });

            $("#city_id").change();
        });

        $('#city_id').change(function() {
            var id = $(this).children('option:selected').val();
            $("#district_id").empty();

            var cityArray = new Array();
            $.each(areas[selectP].city, function(idx, obj) {
                if (obj.id == id) {
                    cityArray = obj;
                }
            });

            $.each(cityArray.district, function(idx, obj) {
                var selected = false;
                if (obj.id == selectIndexS) {
                    selected = true;
                }
                $("#district_id").append(new Option(obj.name, obj.id, false, selected));
            });
        });

        // 城市选择开始
        $.each(areas, function(idx, obj) {
            var selected = false;
            if (idx == selectIndexP) {
                selected = true;
            }

            $("#province_id").append(new Option(obj.name, obj.id, false, selected));
            $("#province_id").change();
        });
    });

    // 编辑器
    require(['jquery', 'ckeditor', 'angular'], function () {
        window.form.render();
        window.createEditor('[name="intro"]', {height: 420});
        var app = angular.module("ProductForm", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback() {}
    });

    function coordinateReciever(lat, lng) {
        $("#data_lat").val(lat);
        $("#data_lng").val(lng);
    }
    function deleteItem(object) {
        object.parent().parent().parent().remove();
    }

    $("input[name=upload_photo]").change(function() {
        addPhoto();
    });

    function addPhoto() {
        $("#photo_template").find(".news_article_item").attr("data-tips-image", "332211");
        var img = $("#photo_template").find(".news_article_item");
        var photo = $("input[name=upload_photo]").val();
        img.css('background-image', 'url(' + photo + ')');

        $("#photo_template").find("input[name=photos\\[\\]]").val(photo);

        var html = $("#photo_template").clone();
        var li = document.createElement("li");
        li.innerHTML = html.html();
        $("#upload_select").before(li);
    }
</script>
{/block}

{block name="style"}
<style>
    .panel{border-radius:0}
    .article-right {position:absolute;left:20px;position:absolute;}
    .article-right .layui-input{border-radius:0;border:1px solid #e5e6e7;}
    .article-right .layui-input:hover, .news-right .layui-input:focus{border-color:#e5e6e7!important;}
    .article-right .input-group-addon{background:#fff;border-radius:0;border-color:#e5e6e7;text-align:right}
    .article-right .upload-image-box{width:150px;height:120px;background-size:cover;background-position:center center;}
</style>
{/block}